package com.xiaoma.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import entity.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @Author: xiaoma
 * @Date: 2021/7/9 10:00
 * @description:
 */
@Mapper
@Repository
public interface GoodsDao extends BaseMapper<Goods> {
    //乐观锁 and  stock_count>0
    @Update("update goods set  stock_count =stock_count-#{num}  WHERE id=#{id}  and  stock_count>0")
    Integer lockStock(String id,Integer num);
    @Update("update goods set  stock_count =stock_count+#{num}  WHERE id=#{id}")
    Integer unlockStock(String id,Integer num);
}
